<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                    xmlns:cmp="clr-namespace:Citrix.Cmp;assembly=Citrix.Cmp.Wpf"
                    xmlns:prop="clr-namespace:SkinningSample.Properties">

  <!--=========================================================================================-->
  <!-- Contains styles for presenting content in lists, primarily using ListBox controls. -->
  
  <!-- Style for drawing separator lines. -->
  <Style x:Key="RectangleSeparatorStyle" TargetType="{x:Type Rectangle}">
    <Setter Property="SnapsToDevicePixels" Value="True" />
    <Setter Property="Fill" Value="LightGray" />
    <Setter Property="Height" Value="{DynamicResource {x:Static cmp:DpiScaling.DeviceDependentSeparatorHeightKey}}" />
  </Style>

  <!-- We override the default list box item template to use our skinned colours. We also add a
    default separator line. -->
  <Style x:Key="{x:Type ListBoxItem}" TargetType="{x:Type ListBoxItem}">
    <Setter Property="Background" Value="Transparent"/>
    <Setter Property="HorizontalContentAlignment" Value="{Binding HorizontalContentAlignment, RelativeSource={RelativeSource AncestorType={x:Type ItemsControl}}}"/>
    <Setter Property="VerticalContentAlignment" Value="{Binding VerticalContentAlignment, RelativeSource={RelativeSource AncestorType={x:Type ItemsControl}}}"/>
    <Setter Property="Padding" Value="0"/>
    <Setter Property="FocusVisualStyle" Value="{x:Null}"/>
    <Setter Property="Template">
      <Setter.Value>
        <ControlTemplate TargetType="{x:Type ListBoxItem}">
          <Grid>
            <Grid.RowDefinitions>
              <RowDefinition Height="Auto"/>
              <RowDefinition Height="Auto"/>
            </Grid.RowDefinitions>

            <!-- The border provides the selection highlight. -->
            <Border x:Name="Bd" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}"
                    Background="{TemplateBinding Background}" Padding="{TemplateBinding Padding}"
                    SnapsToDevicePixels="true">
              <ContentPresenter HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
                                SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"
                                VerticalAlignment="{TemplateBinding VerticalContentAlignment}"/>
            </Border>

            <!-- Separator line -->
            <Rectangle Grid.Row="1" Style="{DynamicResource RectangleSeparatorStyle}"/>
          </Grid>
          <ControlTemplate.Triggers>
            <!-- Selected and has focus -->
            <Trigger Property="IsSelected" Value="true">
              <Setter Property="Background" TargetName="Bd" Value="{DynamicResource ActiveSelectionHighlight}"/>
              <Setter Property="Foreground" Value="White"/>
            </Trigger>
          </ControlTemplate.Triggers>
        </ControlTemplate>
      </Setter.Value>
    </Setter>
  </Style>

  <!-- A custom listbox style that removes the listbox item highlight. We often don't use
  the listbox selection mechanism, so we don't want the listbox selection triggering any
  highlights to be drawn. -->
  <Style x:Key="NoSelectionListBoxItem" TargetType="{x:Type ListBoxItem}">
    <Setter Property="Background" Value="Transparent"/>
    <Setter Property="HorizontalContentAlignment" Value="{Binding HorizontalContentAlignment, RelativeSource={RelativeSource AncestorType={x:Type ItemsControl}}}"/>
    <Setter Property="VerticalContentAlignment" Value="{Binding VerticalContentAlignment, RelativeSource={RelativeSource AncestorType={x:Type ItemsControl}}}"/>
    <Setter Property="Padding" Value="0"/>
    <Setter Property="FocusVisualStyle" Value="{x:Null}"/>
    <Setter Property="Template">
      <Setter.Value>
        <ControlTemplate TargetType="{x:Type ListBoxItem}">
          <Grid>
            <Grid.RowDefinitions>
              <RowDefinition Height="Auto"/>
              <RowDefinition Height="Auto"/>
            </Grid.RowDefinitions>

            <Border BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}"
                    Background="{TemplateBinding Background}" Padding="{TemplateBinding Padding}"
                    SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}">
              <ContentPresenter HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
                                SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"
                                VerticalAlignment="{TemplateBinding VerticalContentAlignment}"/>
            </Border>

            <!-- Separator line -->
            <Rectangle x:Name="separator" Grid.Row="1" Style="{DynamicResource RectangleSeparatorStyle}"/>
          </Grid>
        </ControlTemplate>
      </Setter.Value>
    </Setter>
  </Style>

  <!-- Custom style that removes the visible border and shows a "no items" prompt when empty. -->
  <Style x:Key="CleanListboxStyle" TargetType="{x:Type ListBox}">
    <Setter Property="BorderBrush" Value="Transparent"/>
    <Setter Property="BorderThickness" Value="0"/>
    <Setter Property="FocusVisualStyle" Value="{x:Null}"/>
    <Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.ControlTextBrushKey}}"/>
    <Setter Property="HorizontalContentAlignment" Value="Stretch"/>
    <Setter Property="ScrollViewer.HorizontalScrollBarVisibility" Value="Auto"/>
    <Setter Property="ScrollViewer.VerticalScrollBarVisibility" Value="Auto"/>
    <Setter Property="ScrollViewer.CanContentScroll" Value="true"/>
    <Setter Property="ScrollViewer.PanningMode" Value="Both"/>
    <Setter Property="Stylus.IsFlicksEnabled" Value="False"/>
    <Setter Property="VerticalContentAlignment" Value="Center"/>
    <Setter Property="Template">
      <Setter.Value>
        <ControlTemplate TargetType="{x:Type ListBox}">
          <Border Background="{TemplateBinding Background}"
                    BorderBrush="{TemplateBinding BorderBrush}"
                    BorderThickness="{TemplateBinding BorderThickness}" SnapsToDevicePixels="true">

            <Grid>
              <ScrollViewer x:Name="ScrollViewer" Focusable="false" Padding="{TemplateBinding Padding}">
                <ItemsPresenter SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"/>
              </ScrollViewer>

              <!-- The no items prompt, made visible when the list is not empty. -->
              <TextBlock x:Name="NoItemsPrompt" Text="{x:Static prop:Resources.ListboxEmptyPrompt}" Visibility="Collapsed"
                         HorizontalAlignment="Center" VerticalAlignment="Center"
                         Margin="20,0" FontSize="16" Foreground="Gray"/>

            </Grid>
          </Border>
          <ControlTemplate.Triggers>
            <Trigger Property="IsGrouping" Value="true">
              <Setter Property="ScrollViewer.CanContentScroll" Value="false"/>
            </Trigger>
            <!-- Shows the empty prompt when there are no items in the list. -->
            <Trigger Property="HasItems" Value="False">
              <Setter TargetName="ScrollViewer" Property="Visibility" Value="Collapsed"/>
              <Setter TargetName="NoItemsPrompt" Property="Visibility" Value="Visible"/>
            </Trigger>
          </ControlTemplate.Triggers>
        </ControlTemplate>
      </Setter.Value>
    </Setter>
  </Style>

</ResourceDictionary>